package com.bawei.demo_shoppingcar.adapter;

import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bawei.demo_shoppingcar.R;
import com.bawei.demo_shoppingcar.application.ContentData;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import java.util.List;
import java.util.Map;


public class AdvertisePagerViewAdapter extends PagerAdapter {
    List<Map<String, Object>> list;

    public AdvertisePagerViewAdapter(List<Map<String, Object>> listHader) {
        this.list = listHader;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        Map<String, Object> map = list.get(position % list.size());
        ImageView img = (ImageView) map.get("view");
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        img.setLayoutParams(params);
        img.setScaleType(ImageView.ScaleType.FIT_XY);
        ImageLoader.getInstance().displayImage(map.get("url").toString(), img, ContentData.options);
        container.addView(img);
        return img;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
